Public Partial Class FrmListaOrdenAgregar
    Inherits System.Web.UI.Page

    Private TblClientes As CapaDeNegocios.nCliente = New CapaDeNegocios.nCliente
    Private TblOrdenservicio As CapaDeNegocios.nOrdenServicio = New CapaDeNegocios.nOrdenServicio
    Private tblAfectacionOperador As CapaDeNegocios.nAfectacionOperador = New CapaDeNegocios.nAfectacionOperador
    Private tblAfectacionUnidad As CapaDeNegocios.nAfectacionUnidad = New CapaDeNegocios.nAfectacionUnidad
    Private tblSolicitudServicio As CapaDeNegocios.nSolicitudServicio = New CapaDeNegocios.nSolicitudServicio

    Dim IdOrdenServicioInterno As String
    Dim IDOrdenservicioDescInterno As String
    Dim IdClienteDescInterno As String
    Dim IDTipoUnidadDesc1Interno As String
    Dim IDTipoUnidadDesc2Interno As String

    Dim IdClienteInterno As String
    Dim IdTUnidadInterno As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Login") = "Anonimo" Then
            Response.Redirect("/")
        End If

        IdOrdenServicioInterno = Request.QueryString("IdOrdenServicio")
        IDOrdenservicioDescInterno = Request.QueryString("IDOrdenservicioDesc")
        IdClienteDescInterno = Request.QueryString("IdClienteDesc")
        IdClienteInterno = Request.QueryString("IdCliente")
        IdTUnidadInterno = Request.QueryString("IdTUnidad")
        IDTipoUnidadDesc1Interno = Request.QueryString("IDTipoUnidadDesc1")
        IDTipoUnidadDesc2Interno = Request.QueryString("IDTipoUnidadDesc2")

        If Not Page.IsPostBack Then
            IdOrdenServicioInterno = Request.QueryString("IdOrdenServicio")
            IDOrdenservicioDescInterno = Request.QueryString("IDOrdenservicioDesc")
            IdClienteDescInterno = Request.QueryString("IdClienteDesc")
            IdClienteInterno = Request.QueryString("IdCliente")
            IdTUnidadInterno = Request.QueryString("IdTUnidad")
            IDTipoUnidadDesc1Interno = Request.QueryString("IDTipoUnidadDesc1")
            IDTipoUnidadDesc2Interno = Request.QueryString("IDTipoUnidadDesc2")
            BtnImprimir.Visible = False
            lblError.Visible = False

            BtnImprimir.OnClientClick = "javascript:var popup = window.open('../Reportes/RptListadoDeOrdenesDeServicio.aspx',(new Date().getTime()),'Width=900,Height=500,Scrollbars=NO,Resizable=NO,Location=NO,Menubar=NO,Status=NO,Titlebar=NO,Toolbar=NO')"
            llenarCboClientes()
            llenarGVOrdenes()
        End If
    End Sub
    Sub llenarCboClientes()
        CboClientes.DataSource = TblClientes.Listar("", "", "", "", "", "", "", "", "", "", "", "")
        CboClientes.DataTextField = ("RazonSocial")
        CboClientes.DataValueField = ("CodigoCliente")
        CboClientes.DataBind()
    End Sub
    Sub llenarGVOrdenes()
        Dim Cliente As String
        Dim Estado As String


        Cliente = CboClientes.SelectedValue.ToString
        Estado = lblEstado.Text
        If Not (Cliente = "") And Not (Estado = "") Then
            GVOrdenes.DataSource = TblOrdenservicio.OrdenCliente(Cliente, Estado)
            GVOrdenes.DataBind()
            BtnImprimir.Visible = True
            Session("RptListadoDeOrdenesDeServicio") = GVOrdenes.DataSource
            lblError.Visible = False
            GVOrdenes.Visible = True
        Else
            GVOrdenes.Visible = False
            lblError.Visible = True
            BtnImprimir.Visible = False
        End If

    End Sub

    Protected Sub GVOrdenes_RowDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVOrdenes.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim a As LinkButton = e.Row.FindControl("LnkSeleccionar")
            Dim b As HiddenField = e.Row.FindControl("HFCodigoOrdenServicio")
            Dim c As HiddenField = e.Row.FindControl("HFCodigoTUnidad")
            Dim d As String = CboClientes.Items(CboClientes.SelectedIndex).Text
            Dim ev As String = CboClientes.SelectedValue
            Dim f As Label = e.Row.FindControl("lblUnidad")

            a.OnClientClick = "javascript:window.opener.document.getElementById('" + IdOrdenServicioInterno + "').value = '" + b.Value.ToString + "';window.opener.document.getElementById('" + IDOrdenservicioDescInterno + "').value='" + b.Value.ToString + "';window.opener.document.getElementById('" + IdTUnidadInterno + "').value='" + c.Value.ToString + "';window.opener.document.getElementById('" + IdClienteDescInterno + "').value='" + d + "';window.opener.document.getElementById('" + IdClienteInterno + "').value = '" + d + "';window.opener.document.getElementById('" + IDTipoUnidadDesc1Interno + "').value='" + f.Text.ToString + "';window.opener.document.getElementById('" + IDTipoUnidadDesc2Interno + "').value='" + f.Text.ToString + "';window.close();"
        End If

    End Sub

    Protected Sub CboClientes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboClientes.SelectedIndexChanged
        llenarGVOrdenes()
    End Sub



End Class